using System;
using System.Collections.Generic;
using System.Data.SQLite;
using Model;

namespace DAL {
    public class RoomDAL {
        private RoomDAL() {}
        private static RoomDAL _instance;

        public static RoomDAL GetInstance() {
            if (_instance == null) {
                _instance = new RoomDAL();
            }
            return _instance;
        }

        public List<Room> SelectAllRoom() {
            SQLiteDataReader sqLiteDataReader = SqlHelper.GetDataReader(new SQLiteCommand("select * from RoomInfo where DelFlag = 0"));
            List<Room> rooms = new List<Room>();
            while (sqLiteDataReader.Read()) {
                rooms.Add(new Room() {
                    RoomId = int.Parse(sqLiteDataReader["RoomId"].ToString()),
                    RoomName = sqLiteDataReader["RoomName"].ToString(),
                    DelFlag = int.Parse(sqLiteDataReader["DelFlag"].ToString()),
                    RoomMinConsumption = int.Parse(sqLiteDataReader["RoomMinConsumption"].ToString()),
                    SubTime = Convert.ToDateTime(sqLiteDataReader["SubTime"].ToString())
                });
            }
            sqLiteDataReader.Close();
            return rooms;
        }
    }
}